<?php

class News_Model_Catalog extends GM_Model_Abstract
{
    public function getCategoriesByParentId($parentID)
    {
        $parentID = (int) $parentID;
        
        return $this->getResource('Category')->getCategoriesByParentId($parentID);
    }
    
    public function getCategoryChildrenIds($categoryId, $recursive)
    {
        $categories = $this->getCategoriesByParentId($categoryId);
        $cats = array();
        
        foreach ($categories as $category)
        {
            $cats[] = $category->cid;
            if (true === $recursive)
            {
                $cats = array_merge($cats, $this->getCategoryChildrenIds($category->cid, true));
            }
        }
        
        return cats;
    }
    
    public function getParentCategories($category)
    {
        $cats = array($category);
        if (0 == $category->cup)
        {
            return $cats;
        }
        
        $parent = $category->getParentCategory();
        $cats[] = $parent;
        
        if (0 != $parent->cup)
        {
            $cats = array_merge($cats, $this->getParentCategories($parent));
        }
        return $cats;
    }
    
    public function getCategoryById($cid)
    {
         return $this->getResource('Category')->getCategoryById($cid);
    }
}
?>